import 'package:flutter/material.dart';
import 'package:imooc_flutter_2024/pages/home_page.dart';
import 'package:imooc_flutter_2024/pages/login_page.dart';

class NavigatorUtils {
  static BuildContext? context;

  static void setContext(BuildContext context) {
    NavigatorUtils.context = context;
  }

  /// 跳转到指定页面
  static push(BuildContext context, Widget page) {
    Navigator.push(context, MaterialPageRoute(builder: (context) => page));
  }

  /// 跳转到指定页面并且不能返回
  static pushReplace(BuildContext context, Widget page) {
    Navigator.pushReplacement(
        context, MaterialPageRoute(builder: (context) => page));
  }

  static gotoHome(BuildContext context) {
    NavigatorUtils.pushReplace(context, HomePage());
  }

  static gotoLogin() {
    NavigatorUtils.pushReplace(context!, LoginPage());
  }
}
